<template>
  <img :src="image" v-if="async" class="x-image" :style="`width: ${size}px;height: ${size}px;`"/>
</template>

<script>
  export default {
    name: 'x-image',
    props: {
      src: {},
      size: {
        default: 100,
        type: Number
      }
    },
    model: {
      event: 'change',
      prop: 'src'
    },
    data () {
      return {
        image: {},
        async: false
      }
    },
    mounted () {
      this.init()
    },
    methods: {
      init () {
        this.image = this.$ala.urlImage(this.src)
        this.async = true
      }
    },
    watch: {
      viewModel: {
        deep: true,
        handler (val) {
          this.$emit('change', this.image)
        }
      },
      src: {
        deep: true,
        handler (val) {
          this.init()
        }
      }
    }
  }
</script>
